home *** CD-ROM | disk | FTP | other *** search
- unit WideProp;
-
- interface
-
- // Support for WideString properties.
- //
- // Supporting a property of type WideString is a nontrivial task.
- // The Object Inspector supports only ANSI strings, so you need
- // a custom property editor. The property editor can pop up a dialog
- // box where the user can enter a wide string.
- //
- // The TypInfo unit always maps wide strings to ANSI strings,
- // so this unit defines routines for getting and setting a
- // property value in its native WideString format. This turns out
- // to be more difficult than it should be, and requires detailed
- // knowledge of the format of a property infomation record.
- //
- // When declaring a component with a WideString-type property,
- // make sure to declare it with the Stored directive set to False,
- // and override DefineProperties to store the property value as a
- // WideString (call TReader.ReadWideString and TWriter.WriteWideString).
- // Otherwise, Delphi converts the wide string to an ANSI string
- // to store in the DFM.
- //
- // Copyright ⌐ 2000 Tempest Software, Inc.
-
- uses Windows, Messages, SysUtils, Classes, Graphics, DsgnIntf;
-
- // The object inspector does not support wide strings, so the user must
- // edit and view the wide string property value in a separate dialog box.
- // The TWideStringProperty property editor manages the dialog box.
- type
- TWideStringProperty = class(TStringProperty)
- protected
- function GetWideStrValue: WideString;
- function GetWideStrValueAt(Index: Integer): WideString;
- procedure SetWideStrValue(const Value: WideString);
- public
- procedure Edit; override;
- function GetAttributes: TPropertyAttributes; override;
- procedure PropDrawValue(Canvas: TCanvas; const Rect: TRect; Selected: Boolean); override;
- end;
-
- implementation
-
- uses Consts, Controls, Forms, Dialogs, StdCtrls, WideInfo, WideQuery;
-
- { TWideStringProperty }
-
- procedure TWideStringProperty.Edit;
- resourcestring
- sCaption = 'Set Property Value';
- var
- Text: WideString;
- begin
- Text := GetWideStrValue;
- if InputQueryW(sCaption, GetName + ':', Text) then
- SetWideStrValue(Text);
- end;
-
- // Add the paDialog attribute so the user can set the property
- // value in the Wide String dialog box.
- function TWideStringProperty.GetAttributes: TPropertyAttributes;
- begin
- Result := inherited GetAttributes + [paDialog, paReadOnly];
- end;
-
- // Get the property value as a wide string.
- function TWideStringProperty.GetWideStrValue: WideString;
- begin
- Result := GetWideStrValueAt(0);
- end;
-
- function TWideStringProperty.GetWideStrValueAt(Index: Integer): WideString;
- begin
- Result := GetWideStrProp(GetComponent(Index), GetPropInfo);
- end;
-
- procedure TWideStringProperty.PropDrawValue(Canvas: TCanvas;
- const Rect: TRect; Selected: Boolean);
- var
- Value: WideString;
- begin
- Value := GetWideStrValue;
- // Need to ensure a Unicode font.
- Canvas.Font.Name := 'Arial';
- Win32Check(ExtTextOutW(Canvas.Handle, Rect.Left, Rect.Top,
- Eto_Clipped or Eto_Opaque, @Rect,
- PWideChar(Value), Length(Value), nil));
- end;
-
- // Set the property value as a wide string.
- procedure TWideStringProperty.SetWideStrValue(const Value: WideString);
- var
- I: Integer;
- begin
- for I := 0 to PropCount-1 do
- SetWideStrProp(GetComponent(I), GetPropInfo, Value);
- Modified;
- end;
-
- end.
-